﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ThouShaltNotBrick.Models;
using Microsoft.Xna.Framework.Content;

namespace ThouShaltNotBrick.PipelineExtension.Readers
{
    public sealed class BrickStatesContentTypeReader : ContentTypeReader<BrickStatesData>
    {
        #region Overriden Methods
        protected override BrickStatesData Read(ContentReader pInput, BrickStatesData pExistingInstance)
        {
            // NUMBER OF BRICK STATES (int)
            //   NAME (string)
            //   IS_INDESTRUCTIBLE (bool)
            //   TEXTURE_FILE_NAME (string)

            int numBrickStates = pInput.ReadInt32();
            List<BrickStateData> brickStateList = new List<BrickStateData>(numBrickStates);
            for (int i = 0; i < numBrickStates; i++)
            {
                string name = pInput.ReadString();
                bool isIndestructible = pInput.ReadBoolean();
                string textureFileName = pInput.ReadString();
                BrickStateData brickState = new BrickStateData(name, isIndestructible, textureFileName);
                brickStateList.Add(brickState);
            }

            BrickStatesData brickStates = new BrickStatesData(brickStateList);
            return brickStates;
        }
        #endregion
    }
}